#include<iostream>
using namespace std;

const int SIZE = 10005;
int main(int argc, char const *argv[])
{
    // freopen("test.txt","r",stdin);
    int K; cin>>K;
    int arr[SIZE];for(int i=0;i<K;++i)scanf("%d",arr+i);

    int smax = -1;
    int l=0,r=K-1;

    for(int i = 0; i < K;)
    {
        int tmps = 0;
        int j = i;
        while(tmps>=0 && j<K)
        {
            tmps += arr[j]; 
            if(tmps > smax)
            {
                smax = tmps;
                l = i; r = j;
            }
            j++;
        }
        i = j;
    }
    cout<<(smax==-1 ? 0 : smax)<<" "<<arr[l]<<" "<<arr[r];
    return 0;
}
